﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>CheckBox TreeGrid 多选树形表格</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" /><link href="../demo.css" rel="stylesheet" type="text/css" />

    <script src="../scripts/boot.js" type="text/javascript"></script>
    
</head>
<body>
    <h1>CheckBox TreeGrid 多选树形表格</h1>      
    
<div id="treegrid1" class="mini-treegrid" style="width:600px;height:280px;"     
     showTreeIcon="true" 
    treeColumn="taskname" idField="UID" parentField="ParentTaskUID" resultAsTree="false"
    showCheckBox="true" checkRecursive="true"  onbeforenodecheck="onBeforeNodeCheck"
    onpreload="onpreload"
>
    <div property="columns">
        <div type="indexcolumn"></div>
        <div name="taskname" field="Name" width="200">任务名称</div>
        <div field="Duration" width="100">工期</div>
        <div field="Start" width="100" dateFormat="yyyy-MM-dd">开始日期</div>
        <div field="Finish" width="100" dateFormat="yyyy-MM-dd">完成日期</div>
    </div>
</div>

    <div style="padding-top:5px;color:Red;">Note: checkRecursive决定是否联动选择节点</div>
    <br />
    <input type="button" value="setCheckedNodes" onclick="setCheckedNodes()"/>
    <input type="button" value="getCheckedNodes" onclick="getCheckedNodes()"/>
<input type="button" value="loadtreegrid" onclick="loadtreegrid()"/>
    <br />        
    <script type="text/javascript">
        mini.parse();
        var treegrid1=mini.get("treegrid1");
        var datam;
      
      $.ajax({
            url: "tasks.txt", context: document.body,
            success: function (data) {
                if (data) {
                    alert(data);
                    datam = mini.decode(data);
                    
                    treegrid1.loadList(datam, "UID", "ParentTaskUID");
                    treegrid1.set({ allowCellEdit: false,showCheckBox:true });
                }
            }
        });
      
      
          //treegrid1.loadList({},"id","pid");
      function loadtreegrid(){
          treegrid1.loadList(datam, "id", "pid");
          treegrid1.set({ allowCellEdit: false,showCheckBox:true });
      }
      
          function onpreload(e){
            //datat= mini.clone(e.data);
            ////datat=mini.clone(e.sender.getList());
            //e.data={};
          }
      
        function setCheckedNodes() {
            var tree = mini.get("treegrid1");
            tree.setValue("1,2,3,4");
        }
        function getCheckedNodes() {
            var tree = mini.get("treegrid1");
            var value = tree.getValue();
            alert(value);

        }
        //--------------------------------
        function onBeforeNodeCheck(e) {
            var tree = e.sender;
            var node = e.node;
            if (tree.hasChildren(node)) {
                e.cancel = true;
            }
        }
       
    </script>

</body>
</html>